package mvc.com.controls
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import mvc.com.events.CustomEvent;
	import mvc.com.models.ModelAddMessage;

	public class ControlAddMessage extends MovieClip
	{
		private var viewModelMessage:ModelAddMessage;	
		private var controlApp:MovieClip;
		private var btnAdd:MovieClip,btnRemove:MovieClip;
		private var txtMessaage:TextField;
		
		public function ControlAddMessage($controlApp:MovieClip)
		{			
			super();		
			this.controlApp=$controlApp;
			init();
		}
		private function init():void
		{
			btnAdd=controlApp.buttonAdd_mc;
			btnRemove=controlApp.buttonRemove_mc;
			
			btnAdd.label="addMess";
			btnRemove.label="removeMess";
			
			btnAdd.buttonMode=btnRemove.buttonMode=true;
			btnAdd.mouseChildren=btnRemove.mouseChildren=false;
			btnAdd.label_txt.text="Add Message";
			btnRemove.label_txt.text="Remove Message";
			
			txtMessaage=controlApp.message_txt;
			/* get model */
			viewModelMessage=new ModelAddMessage();
			viewModelMessage.addEventListener(CustomEvent.ON_ADD_MESSAGE,onViewMessage);
			/* add button click */
			btnAdd.addEventListener(MouseEvent.CLICK,listenerClick);
			btnRemove.addEventListener(MouseEvent.CLICK,listenerClick);
		}
		private function listenerClick(evt:MouseEvent):void
		{
			if(evt.target.label=="addMess"){
				viewModelMessage.doAdd();
			}else{
				viewModelMessage.doRemove();
			}
		}
		private function onViewMessage(evt:CustomEvent):void
		{
			txtMessaage.text=evt.message;			
		}
	}
	/* End Class */
}